package com.action;

import com.opensymphony.xwork2.Preparable;

/**
 * 
 * <p>功能描述:分页列表基类，继承此基类必须调整struts2配置中拦截器顺序，
 * 让params拦截在prepare拦截之前，
 * 可以用paramsPrepareParamsStack这组拦截器组</p>
 * @author  <a href="mailto: zhuyoulong@gtss.com.cn">zhuyoulong</a>
 * @create_date 2008-10-23
 * @version $ Revision: 1.0
 */
@SuppressWarnings("serial")
public abstract class PageAction extends BaseAction implements Preparable {
	
	int page = 0;
	PageBean pageBean;
	String pageString="";
	int pagesize = PageBean.PAGE_SIZE;
	public String href = "";
	public void prepare() throws Exception {
		int total = supportTotalCount();
		int pageSize = supportPageSize();
		//pageBean = new PageBean(total, page);
		pageBean = new PageBean(total, page, pageSize);
		setPageString("","");
		
	}
	
	/**
	 * 提供总记录数，分页用，子类必须实现此方法
	 * @return
	 */
	public abstract int supportTotalCount();
	
	/**
	 * 提供每页显示条数，分页用，子类可覆盖此方法
	 * @return
	 */
	public int supportPageSize(){
		return pagesize;
	}
	

	public PageBean getPageBean() {
		return pageBean;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getPagesize() {
		return pagesize;
	}

	public void setPagesize(int pagesize) {
		this.pagesize = pagesize;
	}

	public String getPageString() {
		return pageString;
	}

	/**
	 * 
	 * @param pageString
	 * @param href  搜索参数
	 */
	public void setPageString(String pageString,String href) {
		if(href==null){
			href="";
		}
		pageString += "<a href=\"?page="+pageBean.getFirstPage()+href+"\">首页</a>"
		 + " <a href=\"?page="+pageBean.getPrePage()+href+"\">上一页</a>"
		 + " <a href=\"?page="+pageBean.getNextPage()+href+"\">下一页</a>"
		 + " <a href=\"?page="+pageBean.getTotalPage()+href+"\">尾页</a>"
		 + " ("+pageBean.page+"/"+pageBean.totalPage+") 总记录数:"+pageBean.total+"";
		
//		+ " <INPUT TYPE=\"button\" value='跳转'"
//		+ " onClick=\"location='?page='+go2.value+'\"> <INPUT"
//		+" TYPE=\"text\" NAME=\"go2\" size=3"
//		+" onKeyDown=\"if(event.keyCode==13)location='?page='+this.value+'\">页";
	
		this.pageString = pageString;
	}

	public String getHref() {
		return href;
	}

	public void setHref(String href) {
		this.href = href;
	}

	

}
